# -*- coding: UTF-8; indent-tabs-mode:nil; tab-width:4 -*-

# This file is part of DITA DTD Generator.
#
# DITA DTD Generator is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# DITA DTD Generator is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with DITA DTD Generator.  If not, see <http://www.gnu.org/licenses/>.

import ditagen.dita
from ditagen.dtdgen import Attribute as Attribute
from ditagen.dtdgen import ParameterEntity as ParameterEntity

# Elements
#####################################################################

class TopicElement(ditagen.dita.DitaElement):
    """Topic element."""
    _name = u"topic"
    _cls = u"- topic/topic "
    _model = """(%%title;), (%%titlealts;)?,
        (%%shortdesc; | %%abstract;)%(shortdesc)s,
        (%%prolog;)?, (%%body;)?, (%%related-links;)?%(nested)s"""
    #(%%%s-info-types;)*
    _attrs = [
        Attribute("id", "ID", "#REQUIRED"),
        Attribute("conref", "CDATA", "#IMPLIED"),
        ParameterEntity("select-atts"),
        ParameterEntity("localization-atts"),
        ParameterEntity("arch-atts"),
        Attribute("outputclass", "CDATA", "#IMPLIED"),
    ]
class ConceptElement(ditagen.dita.DitaElement):
    """Concept element."""
    _name = u"concept"
    _cls = u"- topic/topic concept/concept "
    _model = """(%%title;), (%%titlealts;)?,
        (%%shortdesc; | %%abstract;)%(shortdesc)s,
        (%%prolog;)?, (%%conbody;)?, (%%related-links;)?%(nested)s"""
    _attrs = [
        Attribute("id", "ID", "#REQUIRED"),
        Attribute("conref", "CDATA", "#IMPLIED"),
        ParameterEntity("select-atts"),
        ParameterEntity("localization-atts"),
        ParameterEntity("arch-atts"),
        Attribute("outputclass", "CDATA", "#IMPLIED"),
    ]        
class TaskElement(ditagen.dita.DitaElement):
    """Task element."""
    _name = u"task"
    _cls = u"- topic/topic task/task "
    _model = """(%%title;), (%%titlealts;)?,
        (%%shortdesc; | %%abstract;)%(shortdesc)s,
        (%%prolog;)?, (%%taskbody;)?,
        (%%related-links;)?%(nested)s"""
    _attrs = [
        Attribute("id", "ID", "#REQUIRED"),
        Attribute("conref", "CDATA", "#IMPLIED"),
        ParameterEntity("select-atts"),
        ParameterEntity("localization-atts"),
        ParameterEntity("arch-atts"),
        Attribute("outputclass", "CDATA", "#IMPLIED"),
    ]
class ReferenceElement(ditagen.dita.DitaElement):
    """Reference element."""
    _name = u"reference"
    _cls = u"- topic/topic reference/reference "
    _model = """(%%title;), (%%titlealts;)?,
        (%%shortdesc; | %%abstract;)%(shortdesc)s,
        (%%prolog;)?, (%%refbody;)?, (%%related-links;)?%(nested)s"""
    _attrs = [
        Attribute("id", "ID", "#REQUIRED"),
        Attribute("conref", "CDATA", "#IMPLIED"),
        ParameterEntity("select-atts"),
        ParameterEntity("localization-atts"),
        ParameterEntity("arch-atts"),
        Attribute("outputclass", "CDATA", "#IMPLIED"),
    ]
class LearningBaseElement(ditagen.dita.DitaElement):
    """Learning Base element."""
    _name = u"learningBase"
    _cls = u"- topic/topic learningBase/learningBase "
    _model = """((%%title;),
                (%%titlealts;)?, 
                (%%shortdesc; | %%abstract;)?,
                (%%prolog;)?,
                (%%learningBasebody;),
                (%%related-links;)?,
                %(nested)s"""
    _attrs = [
        Attribute("id", "ID", "#REQUIRED"),
        Attribute("conref", "CDATA", "#IMPLIED"),
        ParameterEntity("select-atts"),
        ParameterEntity("localization-atts"),
        ParameterEntity("arch-atts"),
        Attribute("outputclass", "CDATA", "#IMPLIED"),
    ]
class LearningAssessmentElement(ditagen.dita.DitaElement):
    """Learning Assessment element."""
    _name = u"learningAssessment"
    _cls = u"- topic/topic learningBase/learningBase learningAssessment/learningAssessment "
    _model = """((%%title;),
                (%%titlealts;)?, 
                (%%shortdesc; | %%abstract;)?,
                (%%prolog;)?,
                (%%learningAssessmentbody;),
                (%%related-links;)?,
                %(nested)s"""
    _attrs = [
        Attribute("id", "ID", "#REQUIRED"),
        Attribute("conref", "CDATA", "#IMPLIED"),
        ParameterEntity("select-atts"),
        ParameterEntity("localization-atts"),
        ParameterEntity("arch-atts"),
        Attribute("outputclass", "CDATA", "#IMPLIED"),
    ]

class LearningOverviewElement(ditagen.dita.DitaElement):
    """Learning Overview element."""
    _name = u"learningOverview"
    _cls = None #TODO
    _model = None #TODO
    _attrs = None #TODO

class LearningPlanElement(ditagen.dita.DitaElement):
    """Learning Plan element."""
    _name = u"learningPlan"
    _cls = None #TODO
    _model = None #TODO
    _attrs = None #TODO
    
class LearningSummaryElement(ditagen.dita.DitaElement):
    """Learning Summary element."""
    _name = u"learningSummary"
    _cls = None #TODO
    _model = None #TODO
    _attrs = None #TODO

class LearningContentElement(ditagen.dita.DitaElement):
    """Learning Content element."""
    _name = u"learningContent"
    _cls = None #TODO
    _model = None #TODO
    _attrs = None #TODO

class LearningMapElement(ditagen.dita.DitaElement):
    """Learning Map element."""
    _name = u"learningMap"
    _cls = None #TODO
    _model = None #TODO
    _attrs = None #TODO

class LearningBookMapElement(ditagen.dita.DitaElement):
    """Learning Bookmap element."""
    _name = u"learningBookmap"
    _cls = None #TODO
    _model = None #TODO
    _attrs = None #TODO

class MapElement(ditagen.dita.DitaElement):
    """Map element."""
    _name = u"map"
    _cls = u"- map/map "
    _model = """((%%title;)?,
       (%%topicmeta;)?, 
       (%%anchor; |
        %%data.elements.incl; |
        %%navref; |
        %%reltable; |
        %%topicref;)*)"""
    _attrs = [
        Attribute("title", "CDATA", "#IMPLIED"),
        Attribute("id", "ID", "#REQUIRED"),
        ParameterEntity("conref-atts"),
        Attribute("anchorref", "CDATA", "#IMPLIED"),
        Attribute("outputclass", "CDATA", "#IMPLIED"),
        ParameterEntity("localization-atts"),
        ParameterEntity("topicref-atts"),
        ParameterEntity("select-atts"),
        ParameterEntity("arch-atts"),
    ]
class BookMapElement(ditagen.dita.DitaElement):
    """BookMap element."""
    _name = u"bookmap"
    _cls = u"- map/map bookmap/bookmap "
    _model = """(((%%title;) | 
        (%%booktitle;))?,
        (%%bookmeta;)?, 
        (%%frontmatter;)?,
        (%%chapter;)*, 
        (%%part;)*, 
        (%%appendix;)*,
        (%%backmatter;)?,
        (%%reltable;)*)"""
    _attrs = [
        Attribute("id", "ID", "#REQUIRED"),
        ParameterEntity("conref-atts"),
        Attribute("anchorref", "CDATA", "#IMPLIED"),
        Attribute("outputclass", "CDATA", "#IMPLIED"),
        ParameterEntity("localization-atts"),
        ParameterEntity("topicref-atts"),
        ParameterEntity("select-atts"),
        ParameterEntity("arch-atts"),
    ]

# Topic types
#####################################################################
    
class TopicType(ditagen.dita.Type):
    """Topic topic type."""
    _id = u"topic"
    _file = u"base/dtd/topic" # the .dtd file is at technicalContent
    _title = u"Topic"
    _parent = None
    _root = TopicElement()
class ConceptType(TopicType):
    """Concept topic type."""
    _id = u"concept"
    _file = u"technicalContent/dtd/concept"
    _title = u"Concept"
    _parent = TopicType()
    _root = ConceptElement()
class TaskType(TopicType):
    """Task topic type."""
    _id = u"task"
    _file = u"technicalContent/dtd/task"
    _title = u"Task"
    _parent = TopicType()
    _root = TaskElement()
    def __init__(self):
        TopicType.__init__(self)
        self._required_domains = [StrictTaskbodyConstraints]
class GeneralTaskType(ditagen.dita.ShellType):
    """General Task topic type."""
    def __init__(self):
        ditagen.dita.ShellType.__init__(self, u"generalTask", u"General Task", TaskType())
        self.get_parent()._required_domains = []
class ReferenceType(TopicType):
    """Reference topic type."""
    _id = u"reference"
    _file = u"technicalContent/dtd/reference"
    _title = u"Reference"
    _parent = TopicType()
    _root = ReferenceElement()
class MapType(ditagen.dita.Type):
    """Map topic type."""
    _id = u"map"
    _file = u"base/dtd/map" # the .dtd file is at technicalContent
    _title = u"Map"
    _parent = None
    _root = MapElement()

class BookMapType(MapType):
    """BookMap topic type."""
    _id = u"bookmap"
    _file = u"bookmap/dtd/bookmap"
    _title = u"BookMap"
    _parent = MapType()
    _root = BookMapElement()
    
class MachineryTaskType(TopicType):
    """Machinery Task topic type."""
    _id = u"machineTask"
    _file = u"machineIndustry/dtd/machineTask"
    _title = u"Machinery Task"
    _parent = TopicType()
    _root = TaskElement()
    def __init__(self):
        TopicType.__init__(self)
        self._required_domains = [MachineIndustryTaskbodyConstraints]
        self._alias = TaskType()

class LearningBaseType(TopicType):
    """Learning Base topic type."""
    _id = u"learningBase"
    _file = u"learning/dtd/learningBase"
    _title = u"Learning Base"
    _parent = TopicType()
    _root = LearningBaseElement()
class LearningAssessmentType(LearningBaseType):
    """Learning Assessment topic type."""
    _id = u"learningAssessment"
    _file = u"learning/dtd/learningAssessment"
    _title = u"Learning Assessment"
    _parent = LearningBaseType()
    _root = LearningAssessmentElement()
class LearningOverviewType(LearningBaseType):
    """Learning Overview topic type."""
    _id = u"learningOverview"
    _file = u"learning/dtd/learningOverview"
    _title = u"Learning Overview"
    _parent = LearningBaseType()
    _root = LearningOverviewElement()
class LearningPlanType(LearningBaseType):
    """Learning Plan topic type."""
    _id = u"learningPlan"
    _file = u"learning/dtd/learningPlan"
    _title = u"Learning Plan"
    _parent = LearningBaseType()
    _root = LearningPlanElement()
class LearningSummaryType(LearningBaseType):
    """Learning Summary topic type."""
    _id = u"learningSummary"
    _file = u"learning/dtd/learningSummary"
    _title = u"Learning Summary"
    _parent = LearningBaseType()
    _root = LearningSummaryElement()
class LearningContentType(TopicType): #XXX: not finished
    """Learning Content topic type."""
    _id = u"learningContent"
    _file = u"learning/dtd/learningContent"
    _title = u"Learning Content"
    _parent = LearningBaseType()
    _root = LearningContentElement()
class LearningMapType(ditagen.dita.Type):
    """Learning Map topic type."""
    _id = u"learningMap"
    _file = u"learning/dtd/learningMap"
    _title = u"Learning Map"
    _parent = MapType()
    _root = LearningMapElement()
    def __init__(self):
        Type.__init__(self)
        self._alias = MapType()
class LearningBookMapType(MapType):
    """Learning BookMap topic type."""
    _id = u"learningBookMap"
    _file = u"learning/dtd/learningBookmap"
    _title = u"Learning BookMap"
    _parent = MapType()
    _root = LearningBookMapElement()
    def __init__(self):
        Type.__init__(self)
        self._alias = BookMapType()

class ClassificationMapType(ditagen.dita.Type):
    """Classification Map topic type."""
    _id = u"classifyMap"
    _file = u"subjectScheme/dtd/classifyMap"
    _title = u"Classification Map"
    #_parent = MapType()
    _root = None # TODO
    def __init__(self):
        Type.__init__(self)
        self._alias = MapType()
class SubjectSchemeMapType(MapType):
    """Subject Scheme Map topic type."""
    _id = u"subjectScheme"
    _file = u"subjectScheme/dtd/subjectScheme"
    _title = u"Subject Scheme Map"
    _parent = MapType()
    _root = None # TODO


# Domains
#####################################################################

class Constraints(ditagen.dita.DomainBase):
    """Base class for constraints."""
    _file_suffix = u"Constraint"
    _fpi_suffix = u" Constraint"
    _elements = []
    def get_file_name(self, extension):
        return self._file + "Constraint." + extension

# Domains

class UiDomain(ditagen.dita.Domain):
    """User interface domain."""
    _id = u"ui-d"
    _file = u"technicalContent/dtd/ui"
    _title = u"User Interface"
    _elements = [u"pre", u"keyword", u"ph"]
    _parent = [TopicType]
class HiDomain(ditagen.dita.Domain):
    """Hilight domain."""
    _id = u"hi-d"
    _file = u"base/dtd/highlight"
    _title = u"Highlight"
    _elements = [u"ph"]
    _parent = [TopicType]
class PrDomain(ditagen.dita.Domain):
    """Programmign domain."""
    _id = u"pr-d"
    _file = u"technicalContent/dtd/programming"
    _title = u"Programming"
    _elements = [u"pre", u"keyword", u"ph", u"fig", u"dl"]
    _parent = [TopicType]
class SwDomain(ditagen.dita.Domain):
    """Software development domain."""
    _id = u"sw-d"
    _file = u"technicalContent/dtd/software"
    _title = u"Software"
    _elements = [u"pre", u"keyword", u"ph"]
    _parent = [TopicType]
class UtDomain(ditagen.dita.Domain):
    """Utilities domain."""
    _id = u"ut-d"
    _file = u"base/dtd/utilities"
    _title = u"Utilities"
    _elements = [u"fig"]
    _parent = [TopicType]
class IndexingDomain(ditagen.dita.Domain):
    """Indexing domain."""
    _id = u"indexing-d"
    _file = u"base/dtd/indexing"
    _title = u"Indexing"
    _elements = [u"index-base"]
    _parent = [TopicType, MapType]
class LearningDomain(ditagen.dita.Domain):
    """Learning domain."""
    _id = u"learning-d"
    _file = u"learning/dtd/learning"
    _title = u"Learning"
    _elements = [u"note", u"fig"]
    # XXX: This builds on 
    _parent = [TopicType]
class LearningMetaDomain(ditagen.dita.Domain):
    """Learning metadata domain."""
    _id = u"learningmeta-d"
    _file = u"learning/dtd/learningMetadata"
    _title = u"Learning Metadata"
    _elements = [u"metadata"]
    _parent = [TopicType]
class LearningMapDomain(ditagen.dita.Domain):
    """Learning map domain."""
    _id = u"learningmap-d"
    _file = u"learning/dtd/learningMap"
    _title = u"Learning Map"
    _elements = [u"topicref"]
    _parent = [MapType]
#class MachineIndustryTaskDomain(ditagen.dita.Domain):
#    _id = u"mitask-d"
#    _file = u"machineIndustry/dtd/mitask"
#    _title = u"Machine Industry Task"
#    _elements = [u"section", u"example"]
#    _parent = [TaskType, MachineryTaskType]
class TaskRequirementsDomain(ditagen.dita.Domain):
    """Task requirements domain."""
    _id = u"taskreq-d"
    _file = u"technicalContent/dtd/taskreq"
    _title = u"Machine Industry Task"
    _elements = [u"prereq", u"postreq"]
    _parent = [TaskType]
class HazardStatementDomain(ditagen.dita.Domain):
    """Hazard statement domain."""
    _id = u"hazardstatement-d"
    _file = u"base/dtd/hazardstatement"
    _title = u"Hazard Statement"
    _elements = [u"note"]
    _parent = [TopicType]
class MapGroupDomain(ditagen.dita.Domain):
    """Map group domain."""
    _id = u"mapgroup-d"
    _file = u"base/dtd/mapGroup"
    _title = u"Map Group"
    _elements = [u"topicref"]
    _parent = [MapType]
class AbbreviatedFormDomain(ditagen.dita.Domain):
    """Abbreviated form domain."""
    _id = u"abbreviate-d"
    _file = u"technicalContent/dtd/abbreviate"
    _title = u"Abbreviated Form"
    _elements = [u"term"]
    _parent = [TopicType]
class XNALDomain(ditagen.dita.Domain):
    """XNAL domain."""
    _id = u"xnal-d"
    _file = u"xnal/dtd/xnal"
    _title = u"XNAL"
    _elements = [u"author"]
    _parent = [MapType]
class UserDelayedResolutionDomain(ditagen.dita.Domain):
    """User delayed resolution domain."""
    _id = u"delay-d"
    _file = u"base/dtd/delayResolution"
    _title = u"Delayed Resolution"
    _elements = [u"keywords"]
    _parent = [TopicType, MapType]
class ClassifyDomain(ditagen.dita.Domain):
    """Classify domain."""
    _id = u"classify-d"
    _file = u"subjectScheme/dtd/classify"
    _title = u"Map Subject Classification"
    _elements = [u"topicref", u"reltable"]
    _parent = [TopicType, MapType]
class GlossaryReferenceDomain(ditagen.dita.Domain):
    """Glossary reference domain."""
    _id = u"glossref-d"
    _file = u"technicalContent/dtd/glossref"
    _title = u"Glossary Reference"
    _elements = [u"topicref"]
    _parent = [MapType]

# Constraints

class StrictTaskbodyConstraints(Constraints):
    """Strict taskbody constraints."""
    _id = u"strictTaskbody-c"
    _file = u"technicalContent/dtd/strictTaskbody"
    _title = u"Strict Taskbody"
    _parent = [TaskType]
    _att_id = u"taskbody"
#class MachineIndustryTaskbodyConstraints(Constraints):
#    _id = u"mitaskTaskbody-c"
#    _file = u"machineIndustry/dtd/mitaskTaskbody"
#    _title = u"Machine Industry Taskbody"
#    _parent = [TaskType]
#    _att_id = u"taskbody"
class MachineryTaskbodyConstraints(Constraints):
    """Machinery taskbody constraints."""
    _id = u"machineryTaskbody-c"
    _file = u"machineIndustry/dtd/machineryTaskbody"
    _title = u"Machinery Taskbody"
    _parent = [TaskType]
    _att_id = u"taskbody"
